﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Obj;
using BLL;

public partial class AreaRestrita_PermissaoForm : PageBase
{
    private int PermissaoID;
    protected void Page_Load(object sender, EventArgs e)
    {
        ValidarUsuario();
        if (!IsPostBack)
        {
            if (Session["PermissaoID"] != null)
            {
                PermissaoID = Convert.ToInt32(Session["PermissaoID"]);
                Session["PermissaoID"] = null;
                hdfID.Value = PermissaoID.ToString();

                objPermissao permissao = new objPermissao(PermissaoID);
                BLLPermissao regra = new BLLPermissao();

                permissao = regra.permissao(permissao);
                CarregarTela(permissao);
            }
        }
    }
    protected void CarregarTela(objPermissao permissao)
    {
        txtPermissao.Text = permissao.Descricao;
    }
    protected void btnSalvar_Click(object sender, EventArgs e)
    {
        BLLPermissao Regra = new BLLPermissao();
        objPermissao permissao = new objPermissao(txtPermissao.Text);
        if ((hdfID.Value != null) && (hdfID.Value != ""))
        {
            permissao.PermissaoID = Convert.ToInt32(hdfID.Value);
            Regra.Save(permissao, action.UPDATE);
            ScriptManager.RegisterClientScriptBlock(
            this,
            typeof(Page),
            "ToggleScript",
            "alert('Permissão alterada com sucesso!');window.location.href='Permissao.aspx'",
            true);
        }
        else
        {
            Regra.Save(permissao, action.INSERT);
            ScriptManager.RegisterClientScriptBlock(
            this,
            typeof(Page),
            "ToggleScript",
            "alert('Permissão incluída com sucesso!');window.location.href='Permissao.aspx'",
            true);
        }
    }
}